#include "header/pyramid_room1.h"

OSG_USING_NAMESPACE

double room1_height = 120;
double room1_width = 250;
double room1_depth = 400;
double room1_door1_height = 90;
double room1_door1_width = 70;
double room1_door2_height = 90;
double room1_door2_width = 70;
double room1_door2_move = 100;

NodePtr createRoom1()
{
	Matrix m;
	
	
#ifdef ROOM1_PLANES_ON
	// *********** FrontL ***********
	NodePtr frontL = makePlane(room1_width/2-room1_door1_width/2, room1_height, 50, 50);
	
	TransformPtr tfrontL = Transform::create();
	beginEditCP(tfrontL, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate((room1_width/2-room1_door1_width/2)/2, room1_height/2, room1_depth);
		m.setRotate(Quaternion(Vec3f(0,1,0), M_PI));
		tfrontL->setMatrix(m);
	endEditCP(tfrontL, Transform::MatrixFieldMask);
	
	NodePtr frontLTrans = Node::create();
	beginEditCP(frontLTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		frontLTrans->setCore(tfrontL);
		frontLTrans->addChild(frontL);
	endEditCP(frontLTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);

	//Kammer Boden Texturen laden
	ImagePtr cryptWallDoor1LeftImage = Image::create();
	cryptWallDoor1LeftImage->read("materials/Room_Door1_Left.jpg");  
   
   
	//Aus dem Bild eine Textur machen
	TextureChunkPtr cryptWallDoor1LeftTex = TextureChunk::create();
	beginEditCP(cryptWallDoor1LeftTex);
		cryptWallDoor1LeftTex->setImage(cryptWallDoor1LeftImage);
		cryptWallDoor1LeftTex->setMinFilter(GL_LINEAR);
		cryptWallDoor1LeftTex->setMagFilter(GL_LINEAR);
		cryptWallDoor1LeftTex->setWrapS(GL_REPEAT);
		cryptWallDoor1LeftTex->setWrapT(GL_REPEAT);
		cryptWallDoor1LeftTex->setEnvMode(GL_MODULATE);
	endEditCP(cryptWallDoor1LeftTex);
	  
	SimpleMaterialPtr cryptWallDoor1LeftMat = SimpleMaterial::create();
	beginEditCP(cryptWallDoor1LeftMat);
		//Materialfarbe bei seitlicher Ansicht (Brechungswinkel)
		cryptWallDoor1LeftMat->setAmbient(Color3f(0.3, 0.3, 0.3));    
		//Bestimmt Farbe des Materials
		cryptWallDoor1LeftMat->setDiffuse(Color3f(1.0, 1.0, 1.0));
		cryptWallDoor1LeftMat->setSpecular(Color3f(0.1, 0.1, 0.1));
		cryptWallDoor1LeftMat->addChunk(cryptWallDoor1LeftTex);
	endEditCP(cryptWallDoor1LeftMat);

	
	GeometryPtr cryptWallDoor1LeftGeo = GeometryPtr::dcast(frontL->getCore());
	beginEditCP(cryptWallDoor1LeftGeo);
		cryptWallDoor1LeftGeo->setMaterial(cryptWallDoor1LeftMat);
	endEditCP(cryptWallDoor1LeftGeo);
	
	
	// *********** FrontR ***********
	NodePtr frontR = makePlane(room1_width/2-room1_door1_width/2, room1_height, 50, 50);
	
	TransformPtr tfrontR = Transform::create();
	beginEditCP(tfrontR, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate(room1_width-(room1_width/2-room1_door1_width/2)/2, room1_height/2, room1_depth);
		m.setRotate(Quaternion(Vec3f(0,1,0), M_PI));
		tfrontR->setMatrix(m);
	endEditCP(tfrontR, Transform::MatrixFieldMask);
	
	NodePtr frontRTrans = Node::create();
	beginEditCP(frontRTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		frontRTrans->setCore(tfrontR);
		frontRTrans->addChild(frontR);
	endEditCP(frontRTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
	
	//Kammer Boden Texturen laden
	ImagePtr cryptWallDoor1RightImage = Image::create();
   cryptWallDoor1RightImage->read("materials/Room_Door1_Right.jpg");    
	    
	    
	//Aus dem Bild eine Textur machen
	TextureChunkPtr cryptWallDoor1RightTex = TextureChunk::create();
	beginEditCP(cryptWallDoor1RightTex);
		cryptWallDoor1RightTex->setImage(cryptWallDoor1RightImage);
		cryptWallDoor1RightTex->setMinFilter(GL_LINEAR);
		cryptWallDoor1RightTex->setMagFilter(GL_LINEAR);
		cryptWallDoor1RightTex->setWrapS(GL_REPEAT);
		cryptWallDoor1RightTex->setWrapT(GL_REPEAT);
		cryptWallDoor1RightTex->setEnvMode(GL_MODULATE);
	endEditCP(cryptWallDoor1RightTex);
	  
	SimpleMaterialPtr cryptWallDoor1RightMat = SimpleMaterial::create();
	beginEditCP(cryptWallDoor1RightMat);
		//Materialfarbe bei seitlicher Ansicht (Brechungswinkel)
		cryptWallDoor1RightMat->setAmbient(Color3f(0.3, 0.3, 0.3));    
		//Bestimmt Farbe des Materials
		cryptWallDoor1RightMat->setDiffuse(Color3f(1.0, 1.0, 1.0));
		cryptWallDoor1RightMat->setSpecular(Color3f(0.1, 0.1, 0.1));
		cryptWallDoor1RightMat->addChunk(cryptWallDoor1RightTex);
	endEditCP(cryptWallDoor1RightMat);

	
	GeometryPtr cryptWallDoor1RightGeo = GeometryPtr::dcast(frontR->getCore());
	beginEditCP(cryptWallDoor1RightGeo);
		cryptWallDoor1RightGeo->setMaterial(cryptWallDoor1RightMat);
	endEditCP(cryptWallDoor1RightGeo);
	
	
	// *********** FrontM ***********
	NodePtr frontM = makePlane(room1_door1_width+1/4, room1_height-room1_door1_height, 50, 50);
	
	TransformPtr tfrontM = Transform::create();
	beginEditCP(tfrontM, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate(room1_width/2-1/8, room1_door1_height+(room1_height-room1_door1_height)/2, room1_depth);
		m.setRotate(Quaternion(Vec3f(0,1,0), M_PI));
		tfrontM->setMatrix(m);
	endEditCP(tfrontM, Transform::MatrixFieldMask);
	
	NodePtr frontMTrans = Node::create();
	beginEditCP(frontMTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		frontMTrans->setCore(tfrontM);
		frontMTrans->addChild(frontM);
	endEditCP(frontMTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
	
	//Kammer Boden Texturen laden
	ImagePtr cryptWallDoor1MiddleImage = Image::create();
   cryptWallDoor1MiddleImage->read("materials/Room_Door1_Middle.jpg");    
	    
	    
	//Aus dem Bild eine Textur machen
	TextureChunkPtr cryptWallDoor1MiddleTex = TextureChunk::create();
	beginEditCP(cryptWallDoor1MiddleTex);
		cryptWallDoor1MiddleTex->setImage(cryptWallDoor1MiddleImage);
		cryptWallDoor1MiddleTex->setMinFilter(GL_LINEAR);
		cryptWallDoor1MiddleTex->setMagFilter(GL_LINEAR);
		cryptWallDoor1MiddleTex->setWrapS(GL_REPEAT);
		cryptWallDoor1MiddleTex->setWrapT(GL_REPEAT);
		cryptWallDoor1MiddleTex->setEnvMode(GL_MODULATE);
	endEditCP(cryptWallDoor1MiddleTex);
	  
	SimpleMaterialPtr cryptWallDoor1MiddleMat = SimpleMaterial::create();
	beginEditCP(cryptWallDoor1MiddleMat);
		//Materialfarbe bei seitlicher Ansicht (Brechungswinkel)
		cryptWallDoor1MiddleMat->setAmbient(Color3f(0.3, 0.3, 0.3));    
		//Bestimmt Farbe des Materials
		cryptWallDoor1MiddleMat->setDiffuse(Color3f(1.0, 1.0, 1.0));
		cryptWallDoor1MiddleMat->setSpecular(Color3f(0.1, 0.1, 0.1));
		cryptWallDoor1MiddleMat->addChunk(cryptWallDoor1MiddleTex);
	endEditCP(cryptWallDoor1MiddleMat);

	
	GeometryPtr cryptWallDoor1MiddleGeo = GeometryPtr::dcast(frontM->getCore());
	beginEditCP(cryptWallDoor1MiddleGeo);
		cryptWallDoor1MiddleGeo->setMaterial(cryptWallDoor1MiddleMat);
	endEditCP(cryptWallDoor1MiddleGeo);
	
	
	// *********** Front ***********
	NodePtr front = Node::create();
	beginEditCP(front, Node::CoreFieldMask);
	{
		front->setCore(Group::create());
		front->addChild(frontLTrans);
		front->addChild(frontRTrans);
		front->addChild(frontMTrans);
	}
	endEditCP  (front, Node::CoreFieldMask);
	
	TransformPtr tfront = Transform::create();
	beginEditCP(tfront, Transform::MatrixFieldMask);
		m.setIdentity();
		//m.setTranslate(0, 0, 0);
		//m.setRotate(Quaternion(Vec3f(1,0,0), M_PI));
		tfront->setMatrix(m);
	endEditCP(tfront, Transform::MatrixFieldMask);
	
	NodePtr frontTrans = Node::create();
	beginEditCP(frontTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		frontTrans->setCore(tfront);
		frontTrans->addChild(front);
	endEditCP(frontTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
	


	
	
	// *********** LeftL ***********
	NodePtr leftL = makePlane(room1_depth/2-room1_door2_width/2+room1_door2_move, room1_height, 50, 50);
	
	TransformPtr tleftL = Transform::create();
	beginEditCP(tleftL, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate(0, room1_height/2, (room1_depth/2-room1_door2_width/2+room1_door2_move)/2);
		m.setRotate(Quaternion(Vec3f(0,1,0), M_PI/2));
		tleftL->setMatrix(m);
	endEditCP(tleftL, Transform::MatrixFieldMask);
	
	NodePtr leftLTrans = Node::create();
	beginEditCP(leftLTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		leftLTrans->setCore(tleftL);
		leftLTrans->addChild(leftL);
	endEditCP(leftLTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
	/*
	//Kammer Boden Texturen laden
	ImagePtr cryptWallDoor2LeftImage = Image::create();
   cryptWallDoor2LeftImage->read("materials/Room_Door1_Left.jpg");  
   
   
	//Aus dem Bild eine Textur machen
	TextureChunkPtr cryptWallDoor2LeftTex = TextureChunk::create();
	beginEditCP(cryptWallDoor2LeftTex);
		cryptWallDoor2LeftTex->setImage(cryptWallDoor2LeftImage);
		cryptWallDoor2LeftTex->setMinFilter(GL_LINEAR);
		cryptWallDoor2LeftTex->setMagFilter(GL_LINEAR);
		cryptWallDoor2LeftTex->setWrapS(GL_REPEAT);
		cryptWallDoor2LeftTex->setWrapT(GL_REPEAT);
		cryptWallDoor2LeftTex->setEnvMode(GL_MODULATE);
	endEditCP(cryptWallDoor2LeftTex);
	  
	SimpleMaterialPtr cryptWallDoor2LeftMat = SimpleMaterial::create();
	beginEditCP(cryptWallDoor2LeftMat);
		//Materialfarbe bei seitlicher Ansicht (Brechungswinkel)
		cryptWallDoor2LeftMat->setAmbient(Color3f(0.3, 0.3, 0.3));    
		//Bestimmt Farbe des Materials
		cryptWallDoor2LeftMat->setDiffuse(Color3f(1.0, 1.0, 1.0));
		cryptWallDoor2LeftMat->addChunk(cryptWallDoor2LeftTex);
	endEditCP(cryptWallDoor2LeftMat);


	
	GeometryPtr cryptWallDoor2LeftGeo = GeometryPtr::dcast(leftL->getCore());
	beginEditCP(cryptWallDoor2LeftGeo);
		cryptWallDoor2LeftGeo->setMaterial(cryptWallDoor2LeftMat);
	endEditCP(cryptWallDoor2LeftGeo);
	*/
	
	// *********** LeftR ***********
	NodePtr leftR = makePlane(room1_depth/2-room1_door2_width/2-room1_door2_move, room1_height, 50, 50);
	
	TransformPtr tleftR = Transform::create();
	beginEditCP(tleftR, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate(0, room1_height/2, room1_depth-(room1_depth/2-room1_door2_width/2-room1_door2_move)/2);
		m.setRotate(Quaternion(Vec3f(0,1,0), M_PI/2));
		tleftR->setMatrix(m);
	endEditCP(tleftR, Transform::MatrixFieldMask);
	
	NodePtr leftRTrans = Node::create();
	beginEditCP(leftRTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		leftRTrans->setCore(tleftR);
		leftRTrans->addChild(leftR);
	endEditCP(leftRTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
	/*
	//Kammer Boden Texturen laden
	ImagePtr cryptWallDoor2RightImage = Image::create();
   cryptWallDoor2RightImage->read("materials/Room_Door1_Right.jpg");  
   
   
	//Aus dem Bild eine Textur machen
	TextureChunkPtr cryptWallDoor2RightTex = TextureChunk::create();
	beginEditCP(cryptWallDoor2RightTex);
		cryptWallDoor2RightTex->setImage(cryptWallDoor2RightImage);
		cryptWallDoor2RightTex->setMinFilter(GL_LINEAR);
		cryptWallDoor2RightTex->setMagFilter(GL_LINEAR);
		cryptWallDoor2RightTex->setWrapS(GL_REPEAT);
		cryptWallDoor2RightTex->setWrapT(GL_REPEAT);
		cryptWallDoor2RightTex->setEnvMode(GL_MODULATE);
	endEditCP(cryptWallDoor2RightTex);
	  
	SimpleMaterialPtr cryptWallDoor2RightMat = SimpleMaterial::create();
	beginEditCP(cryptWallDoor2RightMat);
		//Materialfarbe bei seitlicher Ansicht (Brechungswinkel)
		cryptWallDoor2RightMat->setAmbient(Color3f(0.3, 0.3, 0.3));    
		//Bestimmt Farbe des Materials
		cryptWallDoor2RightMat->setDiffuse(Color3f(1.0, 1.0, 1.0));
		cryptWallDoor2RightMat->addChunk(cryptWallDoor2RightTex);
	endEditCP(cryptWallDoor2RightMat);

	
	GeometryPtr cryptWallDoor2RightGeo = GeometryPtr::dcast(leftR->getCore());
	beginEditCP(cryptWallDoor2RightGeo);
		cryptWallDoor2RightGeo->setMaterial(cryptWallDoor2RightMat);
	endEditCP(cryptWallDoor2RightGeo);
	*/
	
	// *********** LeftM ***********
	NodePtr leftM = makePlane(room1_door1_width+2, room1_height-room1_door1_height, 50, 50);
	
	TransformPtr tleftM = Transform::create();
	beginEditCP(tleftM, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate(0, room1_door1_height+(room1_height-room1_door1_height)/2, room1_depth/2+1+room1_door2_move);
		m.setRotate(Quaternion(Vec3f(0,1,0), M_PI/2));
		tleftM->setMatrix(m);
	endEditCP(tleftM, Transform::MatrixFieldMask);
	
	NodePtr leftMTrans = Node::create();
	beginEditCP(leftMTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		leftMTrans->setCore(tleftM);
		leftMTrans->addChild(leftM);
	endEditCP(leftMTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
	/*
	//Kammer Boden Texturen laden
	ImagePtr cryptWallDoor2MiddleImage = Image::create();
   cryptWallDoor2MiddleImage->read("materials/Room_Door1_Middle.jpg");  
   
   
	//Aus dem Bild eine Textur machen
	TextureChunkPtr cryptWallDoor2MiddleTex = TextureChunk::create();
	beginEditCP(cryptWallDoor2MiddleTex);
		cryptWallDoor2MiddleTex->setImage(cryptWallDoor2MiddleImage);
		cryptWallDoor2MiddleTex->setMinFilter(GL_LINEAR);
		cryptWallDoor2MiddleTex->setMagFilter(GL_LINEAR);
		cryptWallDoor2MiddleTex->setWrapS(GL_REPEAT);
		cryptWallDoor2MiddleTex->setWrapT(GL_REPEAT);
		cryptWallDoor2MiddleTex->setEnvMode(GL_MODULATE);
	endEditCP(cryptWallDoor2MiddleTex);
	  
	SimpleMaterialPtr cryptWallDoor2MiddleMat = SimpleMaterial::create();
	beginEditCP(cryptWallDoor2MiddleMat);
		//Materialfarbe bei seitlicher Ansicht (Brechungswinkel)
		cryptWallDoor2MiddleMat->setAmbient(Color3f(0.3, 0.3, 0.3));    
		//Bestimmt Farbe des Materials
		cryptWallDoor2MiddleMat->setDiffuse(Color3f(1.0, 1.0, 1.0));
		cryptWallDoor2MiddleMat->addChunk(cryptWallDoor2MiddleTex);
	endEditCP(cryptWallDoor2MiddleMat);

	
	GeometryPtr cryptWallDoor2MiddleGeo = GeometryPtr::dcast(leftM->getCore());
	beginEditCP(cryptWallDoor2MiddleGeo);
		cryptWallDoor2MiddleGeo->setMaterial(cryptWallDoor2MiddleMat);
	endEditCP(cryptWallDoor2MiddleGeo);
	*/
	
	// *********** Left ***********
	NodePtr left = Node::create();
	beginEditCP(left, Node::CoreFieldMask);
	{
		left->setCore(Group::create());
		left->addChild(leftLTrans);
		left->addChild(leftRTrans);
		left->addChild(leftMTrans);
	}
	endEditCP  (left, Node::CoreFieldMask);
	
	TransformPtr tleft = Transform::create();
	beginEditCP(tleft, Transform::MatrixFieldMask);
		m.setIdentity();
		//m.setTranslate(0, 0, 0);
		//m.setRotate(Quaternion(Vec3f(1,0,0), M_PI));
		tleft->setMatrix(m);
	endEditCP(tleft, Transform::MatrixFieldMask);
	
	NodePtr leftTrans = Node::create();
	beginEditCP(leftTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		leftTrans->setCore(tleft);
		leftTrans->addChild(left);
	endEditCP(leftTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
	
#else
	// *********** Front ***********
	// unten
	// links
	float front_v0[3] = {0, 0, room1_depth};
	// rechts
	float front_v1[3] = {room1_width, 0, room1_depth};
	
	// oben
	// links
	float front_v2[3] = {0, room1_height, room1_depth};
	// rechts
	float front_v3[3] = {room1_width, room1_height, room1_depth};
	
	// Tuer
	// unten links
	float front_v4[3] = {room1_width/2-room1_door1_width/2, 0, room1_depth};
	// oben links
	float front_v5[3] = {room1_width/2-room1_door1_width/2, room1_door1_height, room1_depth};
	// unten rechts
	float front_v6[3] = {room1_width/2+room1_door1_width/2, 0, room1_depth};
	// oben rechts
	float front_v7[3] = {room1_width/2+room1_door1_width/2, room1_door1_height, room1_depth};
	
	// Definieren der benoetigten Typen
	GeoPTypesPtr frontType = GeoPTypesUI8::create();
	beginEditCP (frontType, GeoPTypesUI8::GeoPropDataFieldMask);
	{
		frontType->addValue(GL_QUADS);
	}
	endEditCP (frontType, GeoPTypesUI8::GeoPropDataFieldMask);
	
	// Anzahl der Punkte die fuer die einzelnen Typen benoetigt werden
	GeoPLengthsPtr frontLens = GeoPLengthsUI32::create();    
	beginEditCP (frontLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	{
		frontLens->addValue(12);
	}
	endEditCP (frontLens, GeoPLengthsUI32::GeoPropDataFieldMask);

	// Setzen der Punkte
	GeoPositions3fPtr frontPnts = GeoPositions3f::create();
	beginEditCP (frontPnts, GeoPositions3f::GeoPropDataFieldMask);
	{
		frontPnts->addValue(Pnt3f(front_v0[0], front_v0[1], front_v0[2]));
		frontPnts->addValue(Pnt3f(front_v1[0], front_v1[1], front_v1[2]));
		frontPnts->addValue(Pnt3f(front_v2[0], front_v2[1], front_v2[2]));
		frontPnts->addValue(Pnt3f(front_v3[0], front_v3[1], front_v3[2]));
		frontPnts->addValue(Pnt3f(front_v4[0], front_v4[1], front_v4[2]));
		frontPnts->addValue(Pnt3f(front_v5[0], front_v5[1], front_v5[2]));
		frontPnts->addValue(Pnt3f(front_v6[0], front_v6[1], front_v6[2]));
		frontPnts->addValue(Pnt3f(front_v7[0], front_v7[1], front_v7[2]));
	}
	endEditCP (frontPnts, GeoPositions3f::GeoPropDataFieldMask);

	// Zusammenfuegen der Punkte in die oben angegebenen Formen
	GeoIndicesUI32Ptr frontIndices = GeoIndicesUI32::create();
	beginEditCP (frontIndices, GeoIndicesUI32::GeoPropDataFieldMask);
	{				 
		// links
		frontIndices->addValue(0);
		frontIndices->addValue(4);
		frontIndices->addValue(5);
		frontIndices->addValue(2);
		
		// mitte
		frontIndices->addValue(5);
		frontIndices->addValue(7);
		frontIndices->addValue(3);
		frontIndices->addValue(2);
		
		// rechts
		frontIndices->addValue(1);
		frontIndices->addValue(3);
		frontIndices->addValue(7);
		frontIndices->addValue(6);
		
	}
	endEditCP (frontIndices, GeoIndicesUI32::GeoPropDataFieldMask);
	
	GeoTexCoords2fPtr frontTex = GeoTexCoords2f::create();
	beginEditCP (frontTex);
	{
		frontTex->addValue(Vec2f(front_v0[0]/room1_width, front_v0[1]/room1_height));
		frontTex->addValue(Vec2f(front_v1[0]/room1_width, front_v1[1]/room1_height));


		frontTex->addValue(Vec2f(front_v2[0]/room1_width, front_v2[1]/room1_height));
		frontTex->addValue(Vec2f(front_v3[0]/room1_width, front_v3[1]/room1_height));
				  
		frontTex->addValue(Vec2f(front_v4[0]/room1_width, front_v4[1]/room1_height));
		frontTex->addValue(Vec2f(front_v5[0]/room1_width, front_v5[1]/room1_height));
		frontTex->addValue(Vec2f(front_v6[0]/room1_width, front_v6[1]/room1_height));
		frontTex->addValue(Vec2f(front_v7[0]/room1_width, front_v7[1]/room1_height));
	}
	endEditCP (frontTex);
	
	GeoNormals3fPtr frontNorms = GeoNormals3f::create();
	beginEditCP(frontNorms, GeoNormals3f::GeoPropDataFieldMask);
	{
		for (int x = 0; x < 8; x++)
			 frontNorms->addValue(Vec3f(0,0,1));
	}
	endEditCP (frontNorms, GeoNormals3f::GeoPropDataFieldMask);
	
	ImagePtr image = Image::create();
	image->read("materials/cryptWall.jpg");
			 
	SimpleTexturedMaterialPtr m1 = SimpleTexturedMaterial::create();	     
	// when everything is changed, not setting the mask is ok
	beginEditCP(m1);
	{
		m1->setAmbient      (Color3f(0.3,0.3,0.3));
		m1->setDiffuse      (Color3f(0.8,0.8,0.8));
		m1->setEmission     (Color3f(0.0,0.0,0.0));
		m1->setSpecular     (Color3f(1.0,1.0,1.0));
		m1->setShininess    (20);
		m1->setTransparency (0);
		m1->setColorMaterial(GL_NONE);
		
		m1->setImage	 (image);
		m1->setMinFilter    (GL_LINEAR_MIPMAP_LINEAR);
		m1->setMagFilter    (GL_LINEAR);
		m1->setEnvMode      (GL_MODULATE);
	}
	endEditCP (m1);
	
	// Zusammenfuegen der Eigenschaften
	GeometryPtr frontGeo=Geometry::create();
	beginEditCP (frontGeo, Geometry::TypesFieldMask    |
			 Geometry::LengthsFieldMask   |
			 Geometry::IndicesFieldMask   |
			 Geometry::PositionsFieldMask |
			 Geometry::NormalsFieldMask   |
			 Geometry::MaterialFieldMask  );
	{
		frontGeo->setTypes    (frontType);
		frontGeo->setLengths  (frontLens);
		frontGeo->setIndices  (frontIndices);
		frontGeo->setTexCoords(frontTex);
		frontGeo->setPositions(frontPnts);
		frontGeo->setNormals  (frontNorms);
		frontGeo->setMaterial (m1);
	}
	endEditCP (frontGeo, Geometry::TypesFieldMask    |
			 Geometry::LengthsFieldMask   |
			 Geometry::IndicesFieldMask   |
			 Geometry::PositionsFieldMask |
			 Geometry::NormalsFieldMask   |
			 Geometry::MaterialFieldMask  );

	// Erstellen eines Knotens
	NodePtr front = Node::create();
	beginEditCP(front, Node::CoreFieldMask);
	{
		front->setCore(frontGeo);
	}
	endEditCP (front, Node::CoreFieldMask);
	
	
	
	
	
	// *********** Left ***********
	// unten
	// links
	float left_v0[3] = {0, 0, 0};
	// rechts
	float left_v1[3] = {0, 0, room1_depth};
	
	// oben
	// links
	float left_v2[3] = {0, room1_height, 0};
	// rechts
	float left_v3[3] = {0, room1_height, room1_depth};
	
	// Tuer
	// unten links
	float left_v4[3] = {0, 0, room1_depth/2-room1_door2_width/2+room1_door2_move};
	// oben links
	float left_v5[3] = {0, room1_door2_height, room1_depth/2-room1_door2_width/2+room1_door2_move};
	// unten rechts
	float left_v6[3] = {0, 0, room1_depth/2+room1_door2_width/2+room1_door2_move};
	// oben rechts
	float left_v7[3] = {0, room1_door2_height, room1_depth/2+room1_door2_width/2+room1_door2_move};
	
	// Definieren der benoetigten Typen
	GeoPTypesPtr leftType = GeoPTypesUI8::create();
	beginEditCP (leftType, GeoPTypesUI8::GeoPropDataFieldMask);
	{
		leftType->addValue(GL_QUADS);
	}
	endEditCP (leftType, GeoPTypesUI8::GeoPropDataFieldMask);
	
	// Anzahl der Punkte die fuer die einzelnen Typen benoetigt werden
	GeoPLengthsPtr leftLens = GeoPLengthsUI32::create();    
	beginEditCP (leftLens, GeoPLengthsUI32::GeoPropDataFieldMask);
	{
		leftLens->addValue(12);
	}
	endEditCP (leftLens, GeoPLengthsUI32::GeoPropDataFieldMask);

	// Setzen der Punkte
	GeoPositions3fPtr leftPnts = GeoPositions3f::create();
	beginEditCP (leftPnts, GeoPositions3f::GeoPropDataFieldMask);
	{
		leftPnts->addValue(Pnt3f(left_v0[0], left_v0[1], left_v0[2]));
		leftPnts->addValue(Pnt3f(left_v1[0], left_v1[1], left_v1[2]));
		leftPnts->addValue(Pnt3f(left_v2[0], left_v2[1], left_v2[2]));
		leftPnts->addValue(Pnt3f(left_v3[0], left_v3[1], left_v3[2]));
		leftPnts->addValue(Pnt3f(left_v4[0], left_v4[1], left_v4[2]));
		leftPnts->addValue(Pnt3f(left_v5[0], left_v5[1], left_v5[2]));
		leftPnts->addValue(Pnt3f(left_v6[0], left_v6[1], left_v6[2]));
		leftPnts->addValue(Pnt3f(left_v7[0], left_v7[1], left_v7[2]));
	}
	endEditCP (leftPnts, GeoPositions3f::GeoPropDataFieldMask);

	// Zusammenfuegen der Punkte in die oben angegebenen Formen
	GeoIndicesUI32Ptr leftIndices = GeoIndicesUI32::create();
	beginEditCP (leftIndices, GeoIndicesUI32::GeoPropDataFieldMask);
	{				 
		// links
		leftIndices->addValue(0);
		leftIndices->addValue(4);
		leftIndices->addValue(5);
		leftIndices->addValue(2);
		
		// mitte
		leftIndices->addValue(5);
		leftIndices->addValue(7);
		leftIndices->addValue(3);
		leftIndices->addValue(2);
		
		// rechts
		leftIndices->addValue(1);
		leftIndices->addValue(3);
		leftIndices->addValue(7);
		leftIndices->addValue(6);
		
	}
	endEditCP (leftIndices, GeoIndicesUI32::GeoPropDataFieldMask);
	
	GeoTexCoords2fPtr leftTex = GeoTexCoords2f::create();
	beginEditCP (leftTex);
	{
		leftTex->addValue(Vec2f(left_v0[1]/room1_height, left_v0[2]/room1_depth));
		leftTex->addValue(Vec2f(left_v1[1]/room1_height, left_v1[2]/room1_depth));

		leftTex->addValue(Vec2f(left_v2[1]/room1_height, left_v2[2]/room1_depth));
		leftTex->addValue(Vec2f(left_v3[1]/room1_height, left_v3[2]/room1_depth));
				  
		leftTex->addValue(Vec2f(left_v4[1]/room1_height, left_v4[2]/room1_depth));
		leftTex->addValue(Vec2f(left_v5[1]/room1_height, left_v5[2]/room1_depth));
		leftTex->addValue(Vec2f(left_v6[1]/room1_height, left_v6[2]/room1_depth));
		leftTex->addValue(Vec2f(left_v7[1]/room1_height, left_v7[2]/room1_depth));
	}
	endEditCP (leftTex);
	
	GeoNormals3fPtr leftNorms = GeoNormals3f::create();
	beginEditCP(leftNorms, GeoNormals3f::GeoPropDataFieldMask);
	{
		for (int x = 0; x < 8; x++)
			 leftNorms->addValue(Vec3f(1,0,0));
	}
	endEditCP (leftNorms, GeoNormals3f::GeoPropDataFieldMask);

	// Zusammenfuegen der Eigenschaften
	GeometryPtr leftGeo=Geometry::create();
	beginEditCP (leftGeo, Geometry::TypesFieldMask    |
			 Geometry::LengthsFieldMask   |
			 Geometry::IndicesFieldMask   |
			 Geometry::PositionsFieldMask |
			 Geometry::NormalsFieldMask   |
			 Geometry::MaterialFieldMask  );
	{
		leftGeo->setTypes    (leftType);
		leftGeo->setLengths  (leftLens);
		leftGeo->setIndices  (leftIndices);
		leftGeo->setTexCoords(leftTex);
		leftGeo->setPositions(leftPnts);
		leftGeo->setNormals  (leftNorms);
		leftGeo->setMaterial (m1);
	}
	endEditCP (leftGeo, Geometry::TypesFieldMask    |
			 Geometry::LengthsFieldMask   |
			 Geometry::IndicesFieldMask   |
			 Geometry::PositionsFieldMask |
			 Geometry::NormalsFieldMask   |
			 Geometry::MaterialFieldMask  );


	// Erstellen eines Knotens
	NodePtr left = Node::create();
	beginEditCP(left, Node::CoreFieldMask);
	{
		left->setCore(leftGeo);
	}
	endEditCP (left, Node::CoreFieldMask);
#endif
	
	setName(front, "room1Front");
	setName(left, "room1Left");
	
	
	

	
	
	// *********** Back ***********
	NodePtr back = makePlane(room1_width, room1_height, 50, 50);
	setName(back, "room1Back");
	
	TransformPtr tback = Transform::create();
	beginEditCP(tback, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate(room1_width/2, room1_height/2, 0);
		tback->setMatrix(m);
	endEditCP(tback, Transform::MatrixFieldMask);
	
	NodePtr backTrans = Node::create();
	beginEditCP(backTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		backTrans->setCore(tback);
		backTrans->addChild(back);
	endEditCP(backTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
	
	
	// *********** Right ***********
	NodePtr right = makePlane(room1_depth, room1_height, 50, 50);
	setName(right, "room1Right");
	
	TransformPtr tright = Transform::create();
	beginEditCP(tright, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate(room1_width, room1_height/2, room1_depth/2);
		m.setRotate(Quaternion(Vec3f(0,1,0), -M_PI/2));
		tright->setMatrix(m);
	endEditCP(tright, Transform::MatrixFieldMask);
	
	NodePtr rightTrans = Node::create();
	beginEditCP(rightTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		rightTrans->setCore(tright);
		rightTrans->addChild(right);
	endEditCP(rightTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
	
	
	// *********** Roof ***********
	NodePtr roof = makePlane(room1_width, room1_depth, 50, 50);
	setName(roof, "room1Roof");
	
	TransformPtr troof = Transform::create();
	beginEditCP(troof, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate(room1_width/2, room1_height, room1_depth/2);
		m.setRotate(Quaternion(Vec3f(1,0,0), M_PI/2));
		troof->setMatrix(m);
	endEditCP(troof, Transform::MatrixFieldMask);
	
	NodePtr roofTrans = Node::create();
	beginEditCP(roofTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		roofTrans->setCore(troof);
		roofTrans->addChild(roof);
	endEditCP(roofTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
	
	
	//Kammer Boden Texturen laden
	ImagePtr cryptWallImage = Image::create();
   cryptWallImage->read("materials/cryptWall.jpg");    
	    
	    
	//Aus dem Bild eine Textur machen
	TextureChunkPtr cryptWallTex = TextureChunk::create();
	beginEditCP(cryptWallTex);
		cryptWallTex->setImage(cryptWallImage);
		cryptWallTex->setMinFilter(GL_LINEAR);
		cryptWallTex->setMagFilter(GL_LINEAR);
		cryptWallTex->setWrapS(GL_REPEAT);
		cryptWallTex->setWrapT(GL_REPEAT);
		cryptWallTex->setEnvMode(GL_MODULATE);
	endEditCP(cryptWallTex);
	  
	SimpleMaterialPtr cryptWallMat = SimpleMaterial::create();
	beginEditCP(cryptWallMat);
		//Materialfarbe bei seitlicher Ansicht (Brechungswinkel)
		cryptWallMat->setAmbient(Color3f(0.3, 0.3, 0.3));    
		//Bestimmt Farbe des Materials
		cryptWallMat->setDiffuse(Color3f(1.0, 1.0, 1.0));
		cryptWallMat->setSpecular(Color3f(0.1, 0.1, 0.1));
		cryptWallMat->addChunk(cryptWallTex);
	endEditCP(cryptWallMat);

	
	GeometryPtr cryptWallGeo = GeometryPtr::dcast(back->getCore());
	beginEditCP(cryptWallGeo);
		cryptWallGeo->setMaterial(cryptWallMat);
	endEditCP(cryptWallGeo);
	
	cryptWallGeo = GeometryPtr::dcast(right->getCore());
	beginEditCP(cryptWallGeo);
		cryptWallGeo->setMaterial(cryptWallMat);
	endEditCP(cryptWallGeo);
	
	cryptWallGeo = GeometryPtr::dcast(roof->getCore());
	beginEditCP(cryptWallGeo);
		cryptWallGeo->setMaterial(cryptWallMat);
	endEditCP(cryptWallGeo);
	
	
#ifdef ROOM1_PLANES_ON
	cryptWallGeo = GeometryPtr::dcast(leftL->getCore());
	beginEditCP(cryptWallGeo);
		cryptWallGeo->setMaterial(cryptWallMat);
	endEditCP(cryptWallGeo);
	
	cryptWallGeo = GeometryPtr::dcast(leftR->getCore());
	beginEditCP(cryptWallGeo);
		cryptWallGeo->setMaterial(cryptWallMat);
	endEditCP(cryptWallGeo);
	
	cryptWallGeo = GeometryPtr::dcast(leftM->getCore());
	beginEditCP(cryptWallGeo);
		cryptWallGeo->setMaterial(cryptWallMat);
	endEditCP(cryptWallGeo);
#endif
	
	
	
	
	// *********** Bottom ***********
	//NodePtr bottom = makeBox(room1_width, 10, room1_depth, 50, 50, 10);
	NodePtr bottom = makePlane(room1_width, room1_depth, 50, 50);
	setName(bottom, "room1Bottom");	
	
	TransformPtr tbottom = Transform::create();
	beginEditCP(tbottom, Transform::MatrixFieldMask);
		m.setIdentity();
		m.setTranslate(room1_width/2, 0, room1_depth/2);
		m.setRotate(Quaternion(Vec3f(1,0,0), -M_PI/2));
		tbottom->setMatrix(m);
	endEditCP(tbottom, Transform::MatrixFieldMask);
		
	NodePtr bottomTrans = Node::create();
	beginEditCP(bottomTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
		bottomTrans->setCore(tbottom);
		bottomTrans->addChild(bottom);
	endEditCP(bottomTrans, Node::CoreFieldMask | Node::ChildrenFieldMask);
	
	//Kammer Boden Texturen laden
	ImagePtr cryptBottomImage = Image::create();
   cryptBottomImage->read("materials/cryptBottom.jpg");	 
	
	//Aus dem Bild eine Textur machen
	TextureChunkPtr cryptBottomTex = TextureChunk::create();
	beginEditCP(cryptBottomTex);
		cryptBottomTex->setImage(cryptBottomImage);
		cryptBottomTex->setMinFilter(GL_LINEAR);
		cryptBottomTex->setMagFilter(GL_LINEAR);
		cryptBottomTex->setWrapS(GL_REPEAT);
		cryptBottomTex->setWrapT(GL_REPEAT);
		cryptBottomTex->setScale(0.2);
		cryptBottomTex->setEnvMode(GL_MODULATE);
	endEditCP(cryptBottomTex);
	  
	SimpleMaterialPtr cryptBottomMat = SimpleMaterial::create();
	beginEditCP(cryptBottomMat);
		//Materialfarbe bei seitlicher Ansicht (Brechungswinkel)
		cryptBottomMat->setAmbient(Color3f(0.3, 0.3, 0.3));    
		//Bestimmt Farbe des Materials
		cryptBottomMat->setDiffuse(Color3f(1.0, 1.0, 1.0));
		cryptBottomMat->setSpecular(Color3f(0.1, 0.1, 0.1));
		cryptBottomMat->addChunk(cryptBottomTex);
	endEditCP(cryptBottomMat);

	//Mittelpunkt des Texturtraegers heraus finden und die Textur darauf legen.
	GeometryPtr cryptBottomGeo = GeometryPtr::dcast(bottom->getCore());
	beginEditCP(cryptBottomGeo);
		cryptBottomGeo->setMaterial(cryptBottomMat);
	endEditCP(cryptBottomGeo);


	
	
	
	


	
	

	
		
	// Erstellen eines Knotens
	NodePtr holeRoom1 = Node::create();
	beginEditCP(holeRoom1, Node::CoreFieldMask);
	{
		holeRoom1->setCore(Group::create());
		holeRoom1->addChild(backTrans);
		holeRoom1->addChild(rightTrans);
		holeRoom1->addChild(roofTrans);
		holeRoom1->addChild(bottomTrans);
		
#ifdef ROOM1_PLANES_ON
		holeRoom1->addChild(frontTrans);
		holeRoom1->addChild(leftTrans);
#else
		holeRoom1->addChild(front);
		holeRoom1->addChild(left);
#endif
		
	}
	endEditCP  (holeRoom1, Node::CoreFieldMask);
	
	
	return holeRoom1;
}
